import React, { Component } from 'react';
import { Modal, Table, Button } from 'antd';
import { connect } from 'dva';
import moment from 'moment';

const columns = [
  {
    title: '访问类型',
    dataIndex: 'type',
  },
  {
    title: '访问备注',
    dataIndex: 'remark',
  },
  {
    title: '访问时间',
    dataIndex: 'access_time',
    render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  },
  {
    title: '浏览时长',
    dataIndex: 'diff',
  },
];

class UserEditModal extends Component {
  constructor(...args) {
    super(...args);
    this.state = {
      visible: false,
    };
  }

  showModelHandler = (e) => {
    const { id, user_id } = e;
    this.props.dispatch({
		  type: 'userHistory/getmsg',
		  payload: { id, user_id },
    });
    this.setState({
      visible: true,
    });
  };

  hideModelHandler = (e) => {
    this.setState({
      visible: false,
    });
  };

	// okHandler = () => {
	//     // const { onOk } = this.props;
	//     // this.props.form.validateFields((err, values) => {
	//     //     if (!err) {

	//     //         onOk(values);
	//     //         this.hideModelHandler();
	//     //     }
	//     // });
	// };

  render() {
    const { record, History_msg, loading } = this.props;
		// console.log("render")
		// console.log(History_msg)
    return (
      <span>
      <span >
      <Button onClick={this.showModelHandler.bind(null, record)} type="primary">点我</Button >
    </span>
      <Modal
      title="访问历史"
      visible={this.state.visible}
      onOk={this.hideModelHandler}
      onCancel={this.hideModelHandler}
    >
      {/* dataSource={History_msg}*/}
      <Table columns={columns} dataSource={History_msg} loading={loading} />
    </Modal>
    </span>
    );
  }
}
function mapStateToProps(state) {
	 const loading = state.loading.models.userHistory;
  return { ...state.userHistory, loading };
}
export default connect(mapStateToProps)(UserEditModal);
